<?php

//if we already submitted the file
if (!empty($this->data[model_source_lines]))
{
	//save/cancel links
	$this->helpers->html->link('/spanel/'.$this->name.'/add/', LANG_OK, "class='button'");
	echo " ";
	$this->helpers->html->link('/spanel/'.$this->name.'/add/'.$this->data[file_name], LANG_CANCEL, "class='button'");
	
	//generated model file
	echo '<br /><br />'.LANG_MODEL;
	$this->helpers->html->TableOpen('class = "source" cellspacing = "0" cellpadding="0"');
	
		foreach ($this->data[model_source_lines] as $key=>$value)
		{
			echo "<tr>";
				echo "<td class = 'source_number'>".($key+1)."<td>";
				echo "<td class = 'source'>".$value."<td>";
			echo "<tr>";
		}
	$this->helpers->html->TableClose('');

	//generated controller file
	echo '<br />'.LANG_CONTROLLER;
	$this->helpers->html->TableOpen('class = "source" cellspacing = "0" cellpadding="0"');
	
		foreach ($this->data[controller_source_lines] as $key=>$value)
		{
			echo "<tr>";
				echo "<td class = 'source_number'>".($key+1)."<td>";
				echo "<td class = 'source'>".$value."<td>";
			echo "<tr>";
		}
	$this->helpers->html->TableClose('');
	
	echo '<br />';
	
	//save/cancel links
	$this->helpers->html->link('/spanel/'.$this->name.'/add/', LANG_OK, "class='button'");
	echo " ";
	$this->helpers->html->link('/spanel/'.$this->name.'/add/'.$this->data[file_name], LANG_CANCEL, "class='button'");
	
}
else
{
	$this->helpers->html->Form('');
	$this->helpers->html->TableOpen('class = "eva"');
	
		$this->helpers->htmlx->TableHeaderRow(LANG_VARIABLES, '3');
		
		$this->helpers->htmlx->InputTextRow(LANG_TITLE, 'name', $this->data[name], 'onChange="FillForm();"', '');
		$this->helpers->htmlx->InputTextRow(LANG_SYSTEM_NAME, 'system_name', $this->data[system_name]);
		$this->helpers->htmlx->InputTextRow(LANG_TABLE_NAME, 'table_name', $this->data[table_name], '', '');
		$this->helpers->htmlx->InputTextRow(LANG_DB_CONFIG, 'database_config', $this->data[database_config], '', '');
		$this->helpers->htmlx->InputTextRow(LANG_SP_LIST, 'stored_procedure_list', $this->data[stored_procedure_list], '', '');
		$this->helpers->htmlx->InputTextRow(LANG_SP_LIST_PAGED, 'stored_procedure_list_paged', $this->data[stored_procedure_list_paged], '', '');
		$this->helpers->htmlx->InputTextRow(LANG_SP_UPDATE, 'stored_procedure_update', $this->data[stored_procedure_update], '', '');
		$this->helpers->htmlx->InputTextRow(LANG_SP_GET, 'stored_procedure_get', $this->data[stored_procedure_get], '', '');
		$this->helpers->htmlx->InputTextRow(LANG_SP_DELETE, 'stored_procedure_delete', $this->data[stored_procedure_delete], '', '');
		$this->helpers->htmlx->InputTextRow(LANG_SP_INSERT, 'stored_procedure_insert', $this->data[stored_procedure_insert], '', '');

		$this->helpers->htmlx->CheckBoxRow(LANG_STANDARD_DIRECTORY, "standart_directory", $this->data[standart_directory], "id = 'std_dir' onChange = checkStdDir(this);");
		$this->helpers->htmlx->CheckBoxRow(LANG_STD_ID, "std_id", $this->data[std_id], "id = 'std_id' style='margin-left: 20px;' onChange = checkStdId(this);");
		$this->helpers->htmlx->CheckBoxRow(LANG_STD_NAME, "std_name", $this->data[std_name], "id = 'std_name' style='margin-left: 20px;' onChange = checkStdName(this);");
		$this->helpers->htmlx->CheckBoxRow(LANG_STD_DESCRIPTION, "std_description", $this->data[std_description], "id = 'std_description' style='margin-left: 20px;' onChange = checkStdDescription(this);");	
		
	$this->helpers->html->TableClose('');

	//number of fields
	$elements_count = 5;
	
	for ($i=0; $i<$elements_count; $i++)
	{
		$this->helpers->html->TableOpen('class = "eva"');
			$this->helpers->htmlx->InputTextRow(LANG_APP_NAME, "elements[$i][app_name]", $this->data[elements][$i][app_name], "", "");
			$this->helpers->htmlx->InputTextRow(LANG_NAME, "elements[$i][name]", $this->data[elements][$i][name], "");
			$this->helpers->htmlx->ComboBoxRow(LANG_TYPE, "elements[$i][type]", $this->field_types, $this->data[elements][$i][type], "id = 'elements[$i][type]'");
			$this->helpers->htmlx->SelectBoxRow(LANG_SUB_TYPE, "elements[$i][sub_type]", $this->field_subtypes, $this->data[elements][$i][sub_type]);
			$this->helpers->htmlx->InputTextRow(LANG_TABLE_NAME, "elements[$i][table_name]", $this->data[elements][$i][table_name], "", "");
			$this->helpers->htmlx->InputTextRow(LANG_LENGTH, "elements[$i][length]", $this->data[elements][$i][length], "", "");
			$this->helpers->htmlx->InputTextRow(LANG_MIN_VALUE, "elements[$i][min_value]", $this->data[elements][$i][min_value], "", "");
			$this->helpers->htmlx->InputTextRow(LANG_MAX_VALUE, "elements[$i][max_value]", $this->data[elements][$i][max_value], "", "");
			$this->helpers->htmlx->InputTextRow(LANG_DEFAULT_VALUE, "elements[$i][default_value]", $this->data[elements][$i][default_value], "", "");
			$this->helpers->htmlx->InputTextRow(LANG_BY_DEFAULT, "elements[$i][by_default]", $this->data[elements][$i][by_default], "", "");
			
			$this->helpers->htmlx->CheckBoxRow(LANG_PRIMARY_KEY, "elements[$i][primary_key]" , $this->data[elements][$i][primary_key], "id = 'elements[$i][primary_key]'");
			$this->helpers->htmlx->CheckBoxRow(LANG_NOT_NULL, "elements[$i][not_null]" , $this->data[elements][$i][not_null], "id = 'elements[$i][not_null]'");
		$this->helpers->html->TableClose("");
	}
		
	$this->helpers->htmlx->SubmitTable("submit", "");
		
	$this->helpers->html->FormClose();
}
?>